// 生成编号
const generationNumber = function () {
  var newtiem = String(Date.now());
  for (var j = 1; j < 5; j++) {
    newtiem += parseInt(Math.random() * 10);
  }
  newtiem = newtiem + ''
  return newtiem
}
const moment = (data) => {
  var date = ''
  if (typeof data == 'object') {
    date = data
  } else if (typeof data == 'string' || typeof data == 'number') {
    date = new Date(data)
  } else {
    date = new Date()
  }
  return {
    date: date,
    format: function (type) {
      let date = this.date
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? "0" + MM : MM;
      let d = date.getDate();
      d = d < 10 ? "0" + d : d;
      let h = date.getHours();
      h = h < 10 ? "0" + h : h;
      let m = date.getMinutes();
      m = m < 10 ? "0" + m : m;
      let s = date.getSeconds();
      s = s < 10 ? "0" + s : s;
      if (type) {
        return type.replace('YYYY', y)
          .replace('MM', MM)
          .replace('DD', d)
          .replace('hh', h)
          .replace('mm', m)
          .replace('ss', s)
      } else {
        return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
      }
    }
  }
}
const toTimeString = (value) => {
  let date = new Date(value);
  let y = date.getFullYear();
  let MM = date.getMonth() + 1;
  MM = MM < 10 ? "0" + MM : MM;
  let d = date.getDate();
  d = d < 10 ? "0" + d : d;
  let h = date.getHours();
  h = h < 10 ? "0" + h : h;
  let m = date.getMinutes();
  m = m < 10 ? "0" + m : m;
  let s = date.getSeconds();
  s = s < 10 ? "0" + s : s;
  // return y + "-" + MM + "-" + d + "-" + h;
  return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
  // return y + "-" + MM + "-" + d;
}
module.exports = {
  generationNumber,
  toTimeString,
  moment
}
